package com.hmdp.config;/**
 * ClassName:WebMVCConfig
 * Package:com.hmdp.config
 * Description:
 *
 * @Date:2022/3/23 22:08
 * @Author:lzp
 */

import com.hmdp.utils.interceptor.LoginInterceptor;
import com.hmdp.utils.interceptor.ReflashTokenIntercetor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * ClassName:WebMVCConfig
 */
@Configuration
public class WebMVCConfig implements WebMvcConfigurer {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加登录拦截器
        registry.addInterceptor(new LoginInterceptor())
                .excludePathPatterns(
                        "/user/code",
                        "/user/login",
                        "/blog/hot",
                        "/shop/**",
                        "/shop-type/**",
                        "/voucher/**"
                ).order(1);

        // 添加刷新拦截器,默认拦截所有请求，.addPathPatterns("/**")
        registry.addInterceptor(new ReflashTokenIntercetor(stringRedisTemplate)).order(0);
    }
}
